﻿using INTEX.DataBase;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SETUPABON.xaml
    /// </summary>
    public partial class TWFEVENTSGROUP
    {

        public TWFEVENTSGROUP()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_WFEVENTSGROUP();
            DataContext = MV;
            InitializeComponent();
        }

        public override void NewCommand(object sender, RoutedEventArgs e)
        {

            try
            {   
                dwData = TBMain.NewRow();
                TMV.SetUpNewRow(ref dwData);
                dwData["NEWTIME"] = MV.date;
                Insert(dwData);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void Insert(DataRow _dwWFG)
        {
            TBMain.Rows.InsertAt(_dwWFG, 0);
            vwMaster.View.MoveCurrentToFirst();
            TMV.InsertICC_WFEVENTSGROUP(_dwWFG, app.company);
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {

            try
            {
                dwData = TBMain.NewRow(); 
                SResult = TMV.QueryICC_WFEVENTSGROUP(dwData, 9999);
                MergeData(SResult, true);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void CopyCommand(object sender, RoutedEventArgs e)
        {

            try
            {
                if (dwMaster == null)
                    return;
                dwData = TBMain.NewRow();
                dwData.ItemArray = dwMaster.ItemArray;
                dwData["ROWNID"] = INTEXDBC.GetSeq();
                Insert(dwData);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
            finally
            {

            }
        }

        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.UpdateICC_WFEVENTSGROUP(dwMaster, 0);
        }

        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.DeleteICC_WFEVENTSGROUP(dwMaster, 1);

            filter = "ROWNID='" + dwMaster["ROWNID"].ToString() + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        } 
    }
}
